package com.thoughtworks.preuniversity.biblioteca;

import java.util.List;

/**
 * Created by padmavb on 6/12/14.
 */
//Job:Tell the userInterface to display the available books and movies.
public class ListBooksMovies extends MenuOperation {


    private String jobOfClass;
    public  ListBooksMovies(String jobOfClass){

        this.jobOfClass=jobOfClass;
    }

    @Override
    void doCorrespondingOperation(Library library) {

        UserInterface userInterface=new UserInterface();


        if(this.jobOfClass.equals("List Books")) {

            List<Book> listOfBooksToDisplay=library.getCatalogue();
            if(listOfBooksToDisplay.size()==0){
                userInterface.displayMessage("There are no available books in library\n");

            }
            else{

                userInterface.displayMessage("List of available books are");
                userInterface.displayBookFormat();

                for(int index=0;index<listOfBooksToDisplay.size();index++){

                    userInterface.displayBookDetails(listOfBooksToDisplay.get(index));
                }
            }
        }

        else{

            List<Movie> listOfMoviesToDisplay=library.getMovies();
            if(listOfMoviesToDisplay.size()==0){
                userInterface.displayMessage("There are no available movies in library\n");

            }
            else{

                userInterface.displayMessage("List of available movies are");
                userInterface.displayMovieFormat();

                for(int index=0;index<listOfMoviesToDisplay.size();index++){

                    userInterface.displayMovieDetails(listOfMoviesToDisplay.get(index));
                }
            }

        }

    }

    @Override
    String giveJobOfClass() {
        return jobOfClass;
    }
}
